package br.com.iswe.gwt.util.client;

import java.util.Map;

import br.com.iswe.gwt.ui.client.MessagePanel;
import br.com.iswe.gwt.ui.client.PopupValidationHandler;

public abstract class BaseForm {
	
	//TODO:Verificar o q e mais efeciente no codigo JS gerado (Tamanho) se e utilizar a classe utilitaria
	//ou herdar diretament da classe.
	public final BeanMapFormFactory formFactory = new BeanMapFormFactory();
	protected MessagePanel messagePanel = null;
	
	public BaseForm(){
		messagePanel = MessagePanel.getInstance();
		//configura o validation handler default
		setupValidationHandlers();
	}
	
	public BaseForm(MessagePanel messagePanel){
		//configura o validation handler default
		setupValidationHandlers();
	}
	
	protected void setupValidationHandlers(){
		formFactory.addValidatorHandler(new PopupValidationHandler());
	}
	
	public abstract String[] getKeyProperties();
	
	public boolean validate(){
		return formFactory.validate();
	}
	
	public void clear(){
		formFactory.clear();
	}
	
	public Map getMapValues() {
		Map mapTemp = formFactory.getMapValues();
		return mapTemp;
	}
	
	public String getStringProperty(String nome) {
		return (String)formFactory.getProperty(nome);
	}
	
	public Object getProperty(String nome) {
		return formFactory.getProperty(nome);
	}
	
	public void setProperty(String name, String valor) {
		formFactory.setProperty(name, valor);
	}
	
	public void registerListBoxOnLoading(String listBoxName) {
		formFactory.registerListBoxOnLoading(listBoxName);
	}
	
	public void notifyListBoxLoaded(String listBoxName) {
		formFactory.notifyListBoxLoaded(listBoxName);
	}

	public void fillForm(FlatMap bean) {
		formFactory.fillForm(bean);
	}
	
}
